#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QWidget>
#include <QMap>
#include <QStringList>

#include "usermanager.h"
#include "filedialoghandler.h"
#include "uiobjectreader.h"
#include "userconfigmanager.h"
#include "jsonconfigwriter.h"

namespace Ui {
class MainWindow;
}

// 前向声明，避免不必要的头文件包含
class UserService;
class UserRepository;

class MainWindow : public QWidget
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    bool copyUser(const QString &uiFilePath,
                  const QString &srcUser,
                  const QString &newUser,
                  QString &errorMsg);

private slots:
    void importDirectory();
    void moveToShow();
    void moveToHide();
    void on_button_save_clicked();
    void on_comboBox_insert_ui_currentIndexChanged(const QString &uiPath);
    void onUserChanged(const QString &user);
    void onUserCopied(const QString &newUser);
    void on_button_copy_clicked();
    void onSwitchToUser(const QString &user);


private:
    // ==== UI 指针 ====
    Ui::MainWindow *m_ui;

    // ==== 管理器 ====
    UserManager *m_userManager;
    UserConfigManager *m_userConfigManager;

    // ==== 服务层 ====
    JsonConfigWriter *m_jsonconfigwriter;

    // ==== 辅助数据 ====
    QMap<QString, int> m_objectOriginalIndex;
    QStringList m_tempHidden;
    QString m_lastAddedUser;
    QComboBox *combo;
    QString m_uipath;

    // ==== 内部方法 ====
    void loadUiForUser(const QString &uiPath, const QString &user);
};

#endif // MAINWINDOW_H
